import Cookies from "js-cookie";
const TokenKey = "Token";
const EnvKey = "Env";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function getEnv() {
  return Cookies.get(EnvKey) || "dev";
}
export function getUserId() {
  return Number(Cookies.get("userId"));
}

export function getProjectId() {
  const currentItpm = JSON.parse(localStorage.getItem("currentItpm"));
  return currentItpm ? currentItpm.id : "1355377599500VK9E2";
}
export function getProject() {
  const currentItpm = JSON.parse(localStorage.getItem("currentItpm"));
  return currentItpm ? currentItpm.cfname : "融资融券征信系统";
}
export function getCluster() {
  const currentName = JSON.parse(localStorage.getItem("currentNamespace"));
  return currentName ? currentName.cluster_name : "";
}
export function getNamespaceUuid() {
  const currentName = JSON.parse(localStorage.getItem("currentNamespace"));
  return currentName ? currentName.namespace_uuid : "";
}
export function getNamespace() {
  const currentName = JSON.parse(localStorage.getItem("currentNamespace"));
  return currentName ? currentName.namespace_name : "";
}
export function getEbpfSystemId() {
  const currentName = JSON.parse(localStorage.getItem("currentNamespace"));
  return currentName ? currentName.ebpf_system_id : "";
}
export function isEcsAdmin() {
  const roles = JSON.parse(localStorage.getItem("roles"));
  if (!roles) return false;
  return roles?.some((item) => item?.role_name === "ECSAdmin");
}
